public class num783 {
    //给你一个二叉搜索树的根节点 root ，返回 树中任意两不同节点值之间的最小差值
    int min = Integer.MAX_VALUE;
    TreeNode prev = null;
    public int minDiffInBST(TreeNode root) {
        dfs(root);
        return min;
    }

    private void dfs(TreeNode root) {
        if(root == null) {
            return;
        }
        dfs(root.left);
        if(prev != null) {
            min = Math.min(Math.abs(root.val - prev.val),min);
        }
        prev = root;
        dfs(root.right);
    }
}
